package com.chwn.curiousdiary.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import com.chwn.curiousdiary.R;

/**
 * Created by Myshikin on 2017/8/8.
 * 字体设置
 */

public class CustomTextView extends android.support.v7.widget.AppCompatTextView {


    private String[] typeFaces = new String[]{"fonts/gbk.ttf", "fonts/gbk_thin.ttf", "fonts/gbk_middle.ttf", "fonts/gbk_thick.ttf"};


    public CustomTextView(Context context) {
        this(context, null);
    }

    public CustomTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public CustomTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CustomTextView);
        int typeFacePosition = typedArray.getInt(R.styleable.CustomTextView_type_face, -1);

        if (typeFacePosition != -1) {
            Typeface typeFace = Typeface.createFromAsset(getContext().getAssets(), typeFaces[typeFacePosition]);
            setTypeface(typeFace);
        }
        typedArray.recycle();
    }


}
